<template>
  <div class="mui-pages record-member-lists">
    <header class="mui-bar mui-bar-nav">
      <div class="header-common-title flex-justify-start">
        <div class="mui-action-back"><img @click="fn.back()" class="back-btn" src="../../../../static/images/back.png"></div>
        <div class="header-search flex-center">申请补开详情</div>
      </div>
    </header>
    <div class="mui-scroll-wrapper">
      <div class="mui-scroll paddingBottom">
        <ul class="mui-table-view meeting-editor-lists">
          <li class="mui-table-view-cell flex-between-center">
            <b>学习主题：</b>
            <span class="mine-lists-content">{{data.subject}}</span>
          </li>
          <li class="mui-table-view-cell flex-between-center">
            <b>原学习时间：</b>
            <span class="mine-lists-content">{{fn.formatDate(data.beforeBeginTime)}}至{{fn.formatDate(data.beforeEndTime)}}</span>
          </li>
          <li class="mui-table-view-cell flex-between-center">
            <b>申请支部：</b>
            <span class="mine-lists-content">{{data.partyGorupName}}</span>
          </li>
          <li class="mui-table-view-cell flex-between-center">
            <b>申请人：</b>
            <span class="mine-lists-content">{{data.createByName}}</span>
          </li>
          <li class="mui-table-view-cell flex-between-center">
            <b>补开时间：</b>
            <span class="mine-lists-content">{{fn.formatDate(data.patchupTime)}}</span>
          </li>
          <li class="mui-table-view-cell">
            <b>补开原因：</b>
            <p class="organization-lists-title">{{data.patchupReason}}</p>
          </li>
          <li class="mui-table-view-cell">
            <b>备注：</b>
            <p class="organization-lists-title">{{data.remarks}}</p>
          </li>
        </ul>
      </div>
    </div>
    <div class="patch-bottom message-details flex-center">
      <div class="work-message-lists login-form" id="disagree">
        <div @click="confirmMsg('N')" class="sign-start-btn">不同意</div>
      </div>
      <div @click="save('Y')" class="sign-end-btn">同意</div>
    </div>
  </div>
</template>

<script>
  import tools from '@/utils/tools'
  import loginService from '@/service/loginService'
  import _ from 'lodash'
  export default {
    name: '',
    data () {
      return {
        fn: tools,
        data: {},
        list: [],
        msg: '',
        id: '' // approve:审批申请，approveHistory:审批记录
      }
    },
    created () {
      this.loadData()
    },
    methods: {
      jump (type) {
        this.$router.replace({path: '/approve/' + type})
      },
      loadData () {
        let cacheData = this.$store.state['patchDetails' + this.$route.params.id]
        let partyGroupId = cacheData.PARTY_GROUP_ID_
        let data = {
          weekId: cacheData.WEEK_ID_,
          partyGroupId
        }
        loginService.getPactUpDetails(data).then((res) => {
          if (res.code === 200) {
            this.data = _.extend(cacheData, res.data)
          }
        })
      },
      confirmMsg () {
        this.dialog = this.$createDialog({
          type: 'prompt',
          title: '不同意原因',
          prompt: {
            value: '',
            placeholder: '请输入'
          },
          onConfirm: (e, promptValue) => {
            if (!promptValue) {
              return tools.alert('请填写原因！')
            }
            this.msg = promptValue
            this.save('N')
          }
        }).show()
      },
      // 审批
      save (isTy) {
        let weekId = this.data.WEEK_ID_
        let partyGroupId = this.data.PARTY_GROUP_ID_
        let data = {
          id: this.$route.params.id,
          isTy: isTy || '',
          weekId: weekId,
          partyGroupId: partyGroupId
        }
        if (isTy === 'N') {
          data.spReason = this.msg
        }
        loginService.dwbPactchUpApproval(data).then(res => {
          if (res.code !== 200) {
            return tools.tip(res.message)
          }
          tools.tip('审批提交完成')
          tools.back()
        })
      }
    },
    watch: {
      $route (to, from) {
        this.type = to.params.type
      }
    }
  }
</script>

<style lang="">
  input[type='text'] {
    margin-bottom:0;
  }
</style>
